package com.usian.controller;

import com.usian.pojo.TbUser;
import com.usian.service.SSOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author lpf
 * @Date 2022/3/26 下午12:05
 * @ProjectName java134-e-commerce-project
 * @Version 1.0
 * @Description:
 */
@RestController
@RequestMapping(value = "service/sso")
public class SSOController {

    @Autowired
    private SSOService ssoService;

    /**
     * 校验用户名和手机号是否可用
     * @param checkValue
     * @param checkFlag
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "checkUserInfo/{checkValue}/{checkFlag}")
    public Boolean checkUserInfo(@PathVariable("checkValue") String checkValue, @PathVariable("checkFlag") Integer checkFlag) {
        return ssoService.checkUserInfo(checkValue, checkFlag);
    }

    /**
     * 实现用户注册功能
     * @param tbUser
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "userRegister")
    public Integer userRegister(@RequestBody TbUser tbUser){
        return ssoService.userRegister(tbUser);
    }

    /**
     * 用户登录功能
     * @param username
     * @param password
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "userLogin")
    public Map userLogin(@RequestParam("username") String username, @RequestParam("password") String password){
        return ssoService.userLogin(username, password);
    }

    /**
     * 通过token获取登录用户
     * @param token
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "getUserByToken/{token}")
    public TbUser getUserByToken(@PathVariable("token") String token){
        return ssoService.getUserByToken(token);
    }

    /**
     * 用户注销登录
     * @param token
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "logout")
    public Boolean logout(@RequestParam String token){
        return ssoService.logout(token);
    }
}
